<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/10/7
 * Time: 15:59
 */
namespace app\admin\controller;
use think\Db;
class Distance extends Base
{
    /*
     * 距离配置首页+
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $count = Db::name('set_juli')->count();//计算总页面
            $lists = Db::name('set_juli')->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('distance/index');

    }

    /*
     * 修改距离配置
     */
    public function distanceEdit(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'juli_value'=>$juli,
                'update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::name('set_juli')
                ->where('juli_id',$juli_id)
                ->update ($param);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $juli = Db::name('set_juli')->where('juli_id',input('id'))->value('juli_value');
        return $this->fetch('distance/distance_edit',['juli'=>$juli,'id'=>input('id')]);
    }
}